package com.les.ufcg.gerenciador;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.les.ufcg.gerenciador.db.DBAdapter;
import com.les.ufcg.gerenciador.elementos.AdicionarEmprestimo;
import com.les.ufcg.gerenciador.elementos.RemoveActivity;
import com.les.ufcg.gerenciador.elementos.RemoverEmprestimosActivity;
import com.les.ufcg.gerenciador.listar.ListActivity;
import com.les.ufcg.gerenciador.listar.ListarEmprestimosActivity;
import com.les.ufcg.gerenciador.listar.ListarEmprestimosSohMeusActivity;
import com.les.ufcg.gerenciador.sms.SMS;

public class MainActivity extends Activity implements OnItemClickListener {
	
	private DBAdapter db;
	private ListView opcoesPrincipais;
	String[] main_items = {"Adicionar", "Remover", "Listar","Enviar SMS", "Ajuda", "Sobre", "Configurar"};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        db = DBAdapter.getContext(this);
        
        opcoesPrincipais = (ListView)findViewById(R.id.main_list);
        opcoesPrincipais.setOnItemClickListener(this);
        opcoesPrincipais.setAdapter(new ArrayAdapter<String>(this, R.layout.main_list_item, main_items));
    }

    
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		
	  	switch(position) {
	  	
		    case 0: {
		    	Log.d("Adicionar", "Adicionar um novo emprestimo");
		    	startActivity(new Intent(getApplication(), AdicionarEmprestimo.class));
	    	    break;
			}
	    
		    case 1: {
		    	Log.d("Remover", "Remover um emprestimo");
		    	startActivity(new Intent(getApplication(), RemoveActivity.class));
	    	    break;
			}
		    
		    case 2: {
		    	Log.d("Listar", "Lista de emprestimos");
		    	startActivity(new Intent(getApplication(), ListActivity.class));
		    	db.close();
		    	break;
		    }
		    
		    case 3: {
		    	Log.d("Enviar SMS", "Enviar um novo SMS");
		    	startActivity(new Intent(getApplication(), SMS.class));
	        	break;	
		    }
		    
		    case 4: {
		    	showDialogs(R.layout.help_dialog);
		    	break;
		    }
		    case 5: {
		    	showDialogs(R.layout.about_dialog);
		    	break;
		    }
		    case 6: {
		    	Log.d("Configurar", "Configuracao da app");
		    	startActivity(new Intent(getApplication(), SMS.class));
	        	break;	
		    }
		
	  	}
		
		
	}


	private void showDialogs(int id) {
        Dialog aboutD = new Dialog(this);
        aboutD.requestWindowFeature(Window.FEATURE_NO_TITLE);
        aboutD.setContentView(id);
        aboutD.setCanceledOnTouchOutside(true);
        aboutD.show();
	}
    
}